package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CGoodsDetailDao;
import com.hongxun.modules.csg.entity.CGoodsDetailEntity;
import com.hongxun.modules.csg.service.CGoodsDetailService;



@Service("cGoodsDetailService")
public class CGoodsDetailServiceImpl implements CGoodsDetailService {
	@Autowired
	private CGoodsDetailDao cGoodsDetailDao;
	
	@Override
	public CGoodsDetailEntity queryObject(String guid){
		return cGoodsDetailDao.queryObject(guid);
	}
	
	@Override
	public List<CGoodsDetailEntity> queryList(Map<String, Object> map){
		return cGoodsDetailDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cGoodsDetailDao.queryTotal(map);
	}
	
	@Override
	public void save(CGoodsDetailEntity cGoodsDetail){
        if(cGoodsDetail.getGuid()==null||cGoodsDetail.getGuid().equals("")) {

		    cGoodsDetail.setGuid(UUID.randomUUID().toString());
        }
		cGoodsDetailDao.save(cGoodsDetail);
	}
	
	@Override
	public void update(CGoodsDetailEntity cGoodsDetail){
		cGoodsDetailDao.update(cGoodsDetail);
	}
	
	@Override
	public void delete(String guid){
		cGoodsDetailDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cGoodsDetailDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CGoodsDetailEntity> entities) {
		for (CGoodsDetailEntity d : entities) {
			if (d.getGDDatastate().equals("删除")) {
				cGoodsDetailDao.delete(d.getGuid());
			} else {
				CGoodsDetailEntity cGoodsDetailEntity = cGoodsDetailDao.queryObject(d.getGuid());
				if (cGoodsDetailEntity == null) {
					cGoodsDetailDao.save(d);
				} else {
					cGoodsDetailDao.update(d);
				}
			}
		}
	}
	
}
